const publicFun = {
    BuildTree(data, root) {
        var _children = [];
        for (var i in data) {


            data[i]['open'] = true

            data[i]['label'] = data[i].PointName;
            data[i]['id'] = data[i].ID;
            data[i]['parentId'] = data[i].FatherID;
            data[i]['visible'] = true;

            if (data[i].FatherID == root) {
                _children.push(data[i]);
                data[i].children = publicFun.BuildTree(data, data[i].ID);
            }
        }
        return _children;
    },

    getCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    },

    touchMove(touchBar){//拖动的div
        $('.' + touchBar + '').on('touchstart', function (e) {

            var _startTouch = e.originalEvent.targetTouches[0];

            var startY = parseInt(_startTouch.pageY);

            var startTop = $('.' + touchBar + '').parent().css('top')

            if (parseInt(startTop) <= 80) {
                $('.' + touchBar + '').parent().css('top', 80)
            }

            $(this).on('touchmove', function (e) {
                var _endTouch = e.originalEvent.targetTouches[0];

                var dY = parseInt(_endTouch.pageY) - startY;

                if (parseInt($('.' + touchBar + '').parent().css('top')) <= 80) {
                    $('.' + touchBar + '').parent().css('top', 80)
                } else if (parseInt($('.' + touchBar + '').parent().css('top')) > parseInt($('.' + touchBar + '').parent().height()) * 0.75) {
                    $('.' + touchBar + '').parent().css('top', parseInt($('.' + touchBar + '').parent().height()) * 0.75)
                }
                else {
                    $('.' + touchBar + '').parent().css('top', (parseInt(startTop) + dY))
                }

            })
        })
    }
};

export default publicFun